<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增房间信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-roomInfo-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">房间图片：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="roomPicture">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="roomPicture" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">房间对应的公寓ID：</label>
                    <div class="col-sm-8">
                        <input name="roomId" class="form-control" type="number" min="1" step="1" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">房间面积：</label>
                    <div class="col-sm-8">
                        <input name="area" class="form-control" type="number" min="0.01" step="0.01" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">租金类型：</label>
                    <div class="col-sm-8">
                        <select name="rentType" class="form-control m-b" th:with="type=${@dict.getType('rent_type')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">房间类型：</label>
                    <div class="col-sm-8">
                        <input name="roomType" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">房东联系方式：</label>
                    <div class="col-sm-8">
                        <input name="hostPhone" class="form-control" type="tel" pattern="[0-9]{13}" maxlength="13" required>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "room/roomInfo"
        $("#form-roomInfo-add").validate({
            focusCleanup: true
        });

        $("#form-roomInfo-add").validate({
            focusCleanup: true,
            rules: {
                area: {
                    required: true,
                    number: true,
                    min: 0.01
                }
            },
            messages: {
                area: {
                    required: "请输入房间面积",
                    number: "请输入有效的数字",
                    min: "房间面积必须大于0"
                }
            }
        });

        $("#form-roomInfo-add").validate({
            focusCleanup: true,
            rules: {
                area: {
                    required: true,
                    number: true,
                    min: 0.01
                },
                hostPhone: {
                    required: true,
                    digits: true,
                    minlength: 13,
                    maxlength: 13
                }
            },
            messages: {
                area: {
                    required: "请输入房间面积",
                    number: "请输入有效的数字",
                    min: "房间面积必须大于0"
                },
                hostPhone: {
                    required: "请输入房东联系方式",
                    digits: "请输入有效的数字",
                    minlength: "手机号必须是13位数字",
                    maxlength: "手机号必须是13位数字"
                }
            }
        });
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-roomInfo-add').serialize());
            }
        }

        $(".file-upload").fileinput({
            uploadUrl: ctx + 'common/upload',
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        });
    </script>
</body>
</html>